//
//  OrderPayTypeView.m
//  WeiYiMei
//
//  Created by iMac on 2019/4/13.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "OrderPayTypeView.h"

@interface OrderPayTypeView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *wxPayIcon;
@property (nonatomic, strong) UILabel *wxPayLab;
@property (nonatomic, strong) UIButton *wxSelectButton;
@property (nonatomic, strong) UIButton *wxActionButton;

@property (nonatomic, strong) UIImageView *aliPayIcon;
@property (nonatomic, strong) UILabel *aliPayLab;
@property (nonatomic, strong) UIButton *aliSelectButton;
@property (nonatomic, strong) UIButton *aliActionButton;

@property (nonatomic, strong) UIView *sep;

@end

@implementation OrderPayTypeView

- (void)setupSubViews
{
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.textColor = kColor333333;
    self.titleLab.font = [UIFont boldSystemFontOfSize:14];
    self.titleLab.text = @"支付方式";
    [self addSubview:self.titleLab];
    
    self.wxPayIcon = [[UIImageView alloc] init];
    self.wxPayIcon.image = [UIImage imageNamed:@"pay_wechat"];
    [self addSubview:self.wxPayIcon];
    
    self.wxPayLab = [[UILabel alloc] init];
    self.wxPayLab.textColor = kColor333333;
    self.wxPayLab.font = [UIFont systemFontOfSize:14];
    self.wxPayLab.text = @"微信支付";
    [self addSubview:self.wxPayLab];
    
    self.wxSelectButton = [[UIButton alloc] init];
    [self.wxSelectButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [self.wxSelectButton setImage:[UIImage imageNamed:@"checked"] forState:UIControlStateSelected];
    [self addSubview:self.wxSelectButton];
    
    self.aliPayIcon = [[UIImageView alloc] init];
    self.aliPayIcon.image = [UIImage imageNamed:@"pay_alipay"];
    [self addSubview:self.aliPayIcon];
    
    self.aliPayLab = [[UILabel alloc] init];
    self.aliPayLab.textColor = kColor333333;
    self.aliPayLab.font = [UIFont systemFontOfSize:14];
    self.aliPayLab.text = @"支付宝";
    [self addSubview:self.aliPayLab];
    
    self.aliSelectButton = [[UIButton alloc] init];
    [self.aliSelectButton setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [self.aliSelectButton setImage:[UIImage imageNamed:@"checked"] forState:UIControlStateSelected];
    [self addSubview:self.aliSelectButton];
    
    self.sep = [[UIView alloc] init];
    self.sep.backgroundColor = kColorDFDFDF;
    [self addSubview:self.sep];
    
    self.wxActionButton = [[UIButton alloc] init];
    self.wxActionButton.backgroundColor = [UIColor clearColor];
    [self addSubview:self.wxActionButton];
    
    self.aliActionButton = [[UIButton alloc] init];
    self.aliActionButton.backgroundColor = [UIColor clearColor];
    [self addSubview:self.aliActionButton];
    
    [self.wxActionButton addTarget:self action:@selector(wxPayAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.aliActionButton addTarget:self action:@selector(aliPayAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)wxPayAction:(id)sender
{
    self.wxSelectButton.selected = YES;
    self.aliSelectButton.selected = NO;
    if (self.selectPayTypeHandler) {
        self.selectPayTypeHandler(1);
    }
}

- (void)aliPayAction:(id)sender
{
    self.wxSelectButton.selected = NO;
    self.aliSelectButton.selected = YES;
    if (self.selectPayTypeHandler) {
        self.selectPayTypeHandler(2);
    }
}

- (void)setupConstraints
{
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.top.equalTo(self).offset(15);
    }];
    
    [self.sep mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.height.equalTo(@(1.0/kScale));
        make.top.equalTo(self).offset(83);
        make.bottom.equalTo(self).offset(-53);
    }];
    
    [self.wxPayIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.sep.mas_top).offset(-15);
        make.left.equalTo(self).offset(15);
    }];
    
    [self.wxPayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.wxPayIcon);
        make.left.equalTo(self.wxPayIcon.mas_right).offset(10);
    }];
    
    [self.wxSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.wxPayIcon);
        make.right.equalTo(self).offset(-22);
    }];
    
    [self.wxActionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.wxPayIcon);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.sep.mas_top).offset(-5);
    }];
    
    [self.aliPayIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sep.mas_bottom).offset(15);
        make.left.equalTo(self).offset(15);
    }];
    
    [self.aliPayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.aliPayIcon);
        make.left.equalTo(self.aliPayIcon.mas_right).offset(10);
    }];
    
    [self.aliSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.aliPayIcon);
        make.right.equalTo(self).offset(-22);
    }];
    
    [self.aliActionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.aliPayIcon);
        make.left.right.equalTo(self);
        make.top.equalTo(self.sep.mas_bottom).offset(5);
    }];
    
}

@end
